using System.Collections;
using System.Collections.Generic;

public class Ctrl
{
    #region
    private Dictionary<ProcType, Proc> m_ProcDict;

    private Proc m_curProc = null;
    #endregion

    #region Construct
    public Ctrl()
    {
        m_ProcDict = new Dictionary<ProcType, Proc>();

        insertProc(new ProcUpdate());
        insertProc(new ProcSDK());
        insertProc(new ProcInit());
        insertProc(new ProcLogin());
        insertProc(new ProcLobby());
        insertProc(new ProcGame());
    }
    #endregion

    #region Logic
    public void Update()
    {
        if (m_curProc != null && m_curProc.IsInit)
            m_curProc.process();
    }

    public void insertProc(Proc f_proc)
    {
        m_ProcDict.Add(f_proc.type, f_proc);
    }

    public Proc findProc(ProcType f_type)
    {
        Proc v = null;
        m_ProcDict.TryGetValue(f_type, out v);
        return v;
    }

    public void changeProc(ProcType f_type, params object[] param)
    {
        if (m_curProc != null && f_type == m_curProc.type)
            return;
        if(m_curProc != null)
        {
            m_curProc.onEnd();
        }
        m_curProc = findProc(f_type);
        m_curProc.onBegin(param);
    }

    public Proc CurrProc
    {
        get
        {
            return m_curProc;
        }
    }
    #endregion
}